package com.leyou.gateway.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.security.PublicKey;

/**
 * @author Eric
 * @version v1.0
 * @package com.leyou.gateway.config
 * @date 2019/7/8 16:48
 * @description:
 **/
@Data
@Slf4j
@ConfigurationProperties("ly.jwt")
public class JwtProperties implements InitializingBean {

    private String pubKeyPath;

    private PublicKey publicKey;

    private UserTokenProperties user=new UserTokenProperties();

    @Data
  public class UserTokenProperties{

        private String cookieName;
    }

    private PrivilegeTokenProperties app =new PrivilegeTokenProperties();

    @Data
    public class PrivilegeTokenProperties{

        private Long id;
        private String secret;
        private String headerName;
    }



    @Override
    public void afterPropertiesSet()  {

        try {
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            log.error("初始化公钥失败，原因是{}",e.getMessage(),e);
            throw new RuntimeException(e);
        }

    }
}
